/**
 * 
 */
package com.my.test.testnet.talk;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * create date: 2010-10-22 上午11:09:56
 * @author Angela Tao
 * @version 1.0
 *
 */
public class Login implements ActionListener{
	
	private JFrame f = new JFrame("登陆");
	private JLabel l1 = new JLabel("用户名",JLabel.RIGHT);
	private JLabel l2 = new JLabel("IP地址",JLabel.RIGHT);
	private JTextField tf1 = new JTextField(10);
	private JTextField tf2 = new JTextField(10);
	private JButton b1 = new JButton("连接");
	private JButton b2 = new JButton("取消");
	
	private JPanel p1 = new JPanel(new GridLayout(2,2));
	private JPanel p2 = new JPanel();

	/**
	 * 
	 */
	public Login() {
		// TODO Auto-generated constructor stub
		p1.add(l1);
		p1.add(tf1);
		p1.add(l2);
		p1.add(tf2);
		f.add(p1);
		p2.add(b1);
		p2.add(b2);
		f.add(p2,"South");
		
		f.setLocation(200, 200);
		f.setSize(200, 120);
		f.setVisible(true);
		
		b1.setActionCommand("connect");
		
		b1.addActionListener(this);
		
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Login();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		String s = arg0.getActionCommand();
		if("connect".equals(s)){
			String name = tf1.getText();
			String ip = tf2.getText();
			if(!"".equals(name) && !"".equals(ip)){
				f.dispose();
				new TalkClient(name,ip);
			}	
		}
	}
}
